package com.gskj.educms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gskj.educms.entity.CrmBanner;
import com.gskj.educms.mapper.CrmBannerMapper;
import com.gskj.educms.service.ICrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.boot.Banner;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author Connor-G
 * @since 2020-05-20
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements ICrmBannerService {

    @Override
    public List<CrmBanner> getBannerList() {

        // 根据 sort 降序，显现 两条记录
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("sort");

        // last方法 拼接语句 ,只显示 两条记录
        wrapper.last("limit 2");

        List<CrmBanner> crmBanners = baseMapper.selectList(wrapper);

        // TODO 后续需添加到 redis缓存中
        return crmBanners;
    }
}
